package com.api.department.editnotification;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.test.context.ContextConfiguration;
import org.testng.Assert;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;

import com.api.test.AbstractApiTest;
import com.zyncro.api.IDepartmentApiService;
import com.zyncro.api.exceptions.ZyncroApiException;
import com.zyncro.api.model.NotificationApiType;
import com.zyncro.api.model.ObjectResultApi;
import com.zyncro.api.model.SubscriptionEventApiType;

@ContextConfiguration(locations = "classpath:/department/department-toedit.xml")
public class EditNotification extends AbstractApiTest {

	@Value("#{department_toEdit[owner].appId}")
	private String userUrn;

	@Value("#{department_toEdit[owner].password}")
	private String userPassword;

	@Value("#{department_toEdit.urn}")
	private String iddepartment;

	@BeforeClass
	protected void loginUser() throws Exception {

		getApi().login(userUrn, userPassword);
	}

	@Test
	public void testEmailFileNotifications() throws ZyncroApiException {
		NotificationApiType notificationType = NotificationApiType.EMAIL;
		SubscriptionEventApiType eventNotificationType = SubscriptionEventApiType.FILE_GROUP_EVENTS;
		boolean enabled = true;

		ObjectResultApi<String> result = getApi().getService(IDepartmentApiService.class).editNotification(iddepartment, notificationType,
				eventNotificationType, enabled);

		Assert.assertNotNull(result);
	}

	@Test
	public void testEmailMemberNotifications() throws ZyncroApiException {
		NotificationApiType notificationType = NotificationApiType.EMAIL;
		SubscriptionEventApiType eventNotificationType = SubscriptionEventApiType.MEMBERS_EVENTS;
		boolean enabled = true;

		ObjectResultApi<String> result = getApi().getService(IDepartmentApiService.class).editNotification(iddepartment, notificationType,
				eventNotificationType, enabled);

		Assert.assertNotNull(result);
	}

	@Test
	public void testFeedMemberNotifications() throws ZyncroApiException {
		NotificationApiType notificationType = NotificationApiType.FEED;
		SubscriptionEventApiType eventNotificationType = SubscriptionEventApiType.MEMBERS_EVENTS;
		boolean enabled = true;

		ObjectResultApi<String> result = getApi().getService(IDepartmentApiService.class).editNotification(iddepartment, notificationType,
				eventNotificationType, enabled);

		Assert.assertNotNull(result);
	}

	@Test
	public void testFeedMessagesNotifications() throws ZyncroApiException {
		NotificationApiType notificationType = NotificationApiType.FEED;
		SubscriptionEventApiType eventNotificationType = SubscriptionEventApiType.MESSAGES_EVENTS;
		boolean enabled = true;

		ObjectResultApi<String> result = getApi().getService(IDepartmentApiService.class).editNotification(iddepartment, notificationType,
				eventNotificationType, enabled);

		Assert.assertNotNull(result);
	}
}
